<template>
	<Layout>
		<Form ref="form1" :model="form1" :label-width="120">
			<Row v-show="!switchFlag" class="query-form" style="padding-top: 10px">
				<Col span="8">
				<FormItem label="车辆名称：" prop="carName">
					<Input class="query-form-el" type="text" v-model="form1.carName" clearable></Input>
				</FormItem>
				</Col>
				<Col span="8">
				<FormItem label="车牌号：" prop="plateNumber">
					<Input class="query-form-el" type="text" v-model="form1.plateNumber" clearable></Input>
				</FormItem>
				</Col>
				<Col span="8">
				<Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
				<Button @click="reset" class="ivu-btn-reset">重置</Button>
				<Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
				</Col>
			</Row>
			<Row v-show="switchFlag" class="query-form" style="padding-top: 10px">
				<Col span="8">
				<FormItem label="车辆名称：" prop="carName">
					<Input class="query-form-el" type="text" v-model="form1.carName" clearable></Input>
				</FormItem>
				</Col>
				<Col span="8">
				<FormItem label="车牌号：" prop="plateNumber">
					<Input class="query-form-el" type="text" v-model="form1.plateNumber" clearable></Input>
				</FormItem>
				</Col>
				<Col span="8">
				<FormItem label="车辆类型：" prop="carTypeId">
					<Select class="query-form-el" filterable v-model="form1.carTypeId" clearable>
						<Option v-for="item in carTypeList" :value="item.codingCodeId" :key="item.codingCodeId">{{
                                item.codingName }}
						</Option>
					</Select>
				</FormItem>
				</Col>

			</Row>
			<Row v-show="switchFlag" class="query-form">

				<Col span="8">
				<FormItem label="当前状态：" prop="carStatusId">
					<Select class="query-form-el" filterable v-model="form1.carStatusId" clearable>
						<Option v-for="item in carStatusList" :value="item.codingCodeId" :key="item.codingCodeId">{{
                                item.codingName }}
						</Option>
					</Select>
				</FormItem>
				</Col>
				<Col span="8">
				<FormItem label="车辆性质：" prop="workType">
					<Select class="query-form-el" filterable v-model="form1.carPropertyId" clearable>
						<Option v-for="item in carPropertyList" :value="item.codingCodeId" :key="item.codingCodeId">
							{{ item.codingName }}
						</Option>
					</Select>
				</FormItem>
				</Col>
				<Col span="8">
				<Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
				<Button @click="reset" class="ivu-btn-reset">重置</Button>
				<Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
				</Col>
			</Row>
			<Row class="query-form">
				<Col span="24">
					<Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
					<Button type="primary" class="ivu-btn-add"   icon="md-cloud-download" :loading="buttonLoading" @click="exportFormSubmit">导出</Button>
				</Col>
			</Row>
		</Form>

		<Table ref='table' :loading="loading" size="small" :height="tableHeight" no-data-text="没有查询到相关数据!"
			@on-selection-change='getSelectRows' border :columns="columns1" :data="dataTable">
		</Table>
		<Row style="margin-right:10px;">
			<Col span="24">
			<Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
				@on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer
				show-elevator />
			</Col>
		</Row>
		<Modal :title="add?'车辆信息新增':'车辆信息修改'" :transfer=false v-model="model1" :width=600>
			<Form ref="form1datacopy" :model="form1datacopy" :rules="ruleCustom" label-position="top">
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="7">
					<FormItem label="车辆名称：" prop="carName">
						<Input type="text" v-model="form1datacopy.carName"></Input>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车辆编号：" prop="serialNumber">
						<Input type="text" v-model="form1datacopy.serialNumber"></Input>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车牌号：" prop="plateNumber">
						<Input type="text" v-model="form1datacopy.plateNumber"></Input>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="7">
					<FormItem label="车辆类型：" prop="carTypeId">
						<Select filterable v-model="form1datacopy.carTypeId">
							<Option v-for="item in carTypeList" :value="item.codingCodeId" :key="item.codingCodeId">
								{{ item.codingName }}
							</Option>
						</Select>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="当前状态：" prop="carStatusId">
						<Select filterable v-model="form1datacopy.carStatusId">
							<Option v-for="item in carStatusList" :value="item.codingCodeId" :key="item.codingCodeId">
								{{ item.codingName }}
							</Option>
						</Select>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车辆性质：" prop="carPropertyId">
						<Select filterable v-model="form1datacopy.carPropertyId">
							<Option v-for="item in carPropertyList" :value="item.codingCodeId" :key="item.codingCodeId">
								{{ item.codingName }}
							</Option>
						</Select>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="7">
					<FormItem label="车辆型号：" prop="carModel">
						<Input type="text" v-model="form1datacopy.carModel"></Input>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="燃油类别：" prop="gasTypeId">
						<Select filterable v-model="form1datacopy.gasTypeId">
							<Option v-for="item in gasTypeList" :value="item.codingCodeId" :key="item.codingCodeId">
								{{ item.codingName }}
							</Option>
						</Select>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="购买日期：" prop="purchaseDate">
						<DatePicker v-model="form1datacopy.purchaseDate" type="date" placeholder="请输入"></DatePicker>
					</FormItem>
					</Col>
				</Row>

				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="23">
					<FormItem label="所属单位：" prop="belongOrgId">
						<cascaderDom class="query-form-el" style="padding-top: 4px;width: 100%;" ref="carOrg"
							@setOrgInfo="setOrgId" @setOrgName="setOrgName" :currentOrgId="form1datacopy.belongOrgId"
							:currentOrgName="form1datacopy.orgName" :orgTree="true"></cascaderDom>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="11">
					<FormItem label="所有人：" prop="userName">
						<Input type="text" v-model="form1datacopy.userName"></Input>
					</FormItem>
					</Col>
					<Col span="11">
					<FormItem label="年检日期：" prop="inspectDate">
						<DatePicker v-model="form1datacopy.inspectDate" type="date" style="width: 100%;"
							placeholder="请输入"></DatePicker>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="23">
					<FormItem label="所在单位：" prop="workOrgId">
						<cascaderDom class="query-form-el" style="padding-top: 4px;width: 100%;" ref="workOrg"
							@setOrgInfo="setWorkOrgId" @setOrgName="setWorkOrgName"
							:currentOrgId="form1datacopy.workOrgId" :currentOrgName="form1datacopy.workOrgName"
							:orgTree="true"></cascaderDom>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="7">
					<FormItem label="发动机编号：" prop="engineSeq">
						<Input type="text" v-model="form1datacopy.engineSeq"></Input>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车架号：" prop="bodyNumber">
						<Input type="text" v-model="form1datacopy.bodyNumber"></Input>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="生产厂家：" prop="carFactory">
						<Input type="text" v-model="form1datacopy.carFactory"></Input>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="7">
					<FormItem label="车长(CM)：">
						<InputNumber :min="0" v-model="form1datacopy.carLen" style="width: 100%;"></InputNumber>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车宽(CM)：">
						<InputNumber :min="0" v-model="form1datacopy.carWidth" style="width: 100%;"></InputNumber>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车高(CM)：">
						<InputNumber :min="0" v-model="form1datacopy.carHeight" style="width: 100%;"></InputNumber>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="7">
					<FormItem label="车重(KG)：">
						<InputNumber :min="0" v-model="form1datacopy.carWeight" style="width: 100%;"></InputNumber>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="车身颜色：" prop="carColor">
						<Input type="text" v-model="form1datacopy.carColor"></Input>
					</FormItem>
					</Col>
					<Col span="7">
					<FormItem label="厂牌：" prop="carFactoryNumber">
						<Input type="text" v-model="form1datacopy.carFactoryNumber"></Input>
					</FormItem>
					</Col>
				</Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
					<Col span="23">
					<FormItem label="备注：" prop="notes">
						<Input v-model="form1datacopy.notes" type="textarea" :rows="2" />
					</FormItem>
					</Col>
				</Row>
			</Form>
			<div slot="footer">
				<Button type="primary" :loading="buttonLoading" class='ivu-btn-save' @click="submit('form1datacopy')">
					确定
				</Button>
				<Button type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
			</div>
		</Modal>
		<Modal title="车辆信息详情" :transfer=false v-model="model2" :width=800>
			<Row>
				<Col span="24">
				<Form :model="showdata" :label-width="160">
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="车辆名称：" prop="carName">
							{{showdata.carName}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车辆编号：" prop="serialNumber">
							{{showdata.serialNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="车牌号：" prop="plateNumber">
							{{showdata.plateNumber}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车辆类型：" prop="carTypeName">
							{{showdata.carTypeName}}
						</FormItem>
						</Col>

					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="当前状态：" prop="carStatusName">
							{{showdata.carStatusName}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车辆性质：" prop="carPropertyName">
							{{showdata.carPropertyName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="车辆型号：" prop="carModel">
							{{showdata.carModel}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="燃油类别：" prop="gasTypeName">
							{{showdata.gasTypeName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="购买日期：" prop="purchaseDate">
							{{showdata.purchaseDate}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="年检日期：" prop="inspectDate">
							{{showdata.inspectDate}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="所属单位：" prop="orgName">
							{{showdata.orgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="所有人：" prop="userName">
							{{showdata.userName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="所在单位：" prop="workOrgName">
							{{showdata.workOrgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="发动机编号：" prop="engineSeq">
							{{showdata.engineSeq}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车架号：" prop="bodyNumber">
							{{showdata.bodyNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="生产厂家：" prop="carFactory">
							{{showdata.carFactory}}
						</FormItem>
						</Col>

					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="自重(KG)：" prop="carWeight" style="width: 100%;">
							{{showdata.carWeight}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车长(CM)：" prop="carLen" style="width: 100%;">
							{{showdata.carLen}}
						</FormItem>
						</Col>

					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="车宽(CM)：" prop="carWidth" style="width: 100%;">
							{{showdata.carWidth}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车高(CM)：" prop="carHeight" style="width: 100%;">
							{{showdata.carHeight}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="车身颜色：" prop="carColor">
							{{showdata.carColor}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="厂牌：" prop="carFactoryNumber">
							{{showdata.carFactoryNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="备注：" prop="notes">
							{{showdata.notes}}
						</FormItem>
						</Col>
					</Row>
				</Form>
				</Col>
			</Row>
			<div slot="footer">
				<Button class='ivu-btn-save' @click="model2=false">关闭</Button>
			</div>
		</Modal>
	</Layout>
</template>

<script>
	import {
		Api
	} from '../../../../api/index.js'
	import cascaderDom from "../../../../components/cascader-dom.vue"
	import {
		sessionStorage
	} from '../../../../common/cacheUtils.js';

	export default {
		name: "eqCarInfo",
		components: {
			cascaderDom
		},
		data() {
			return {
				currentUser: JSON.parse(sessionStorage('userId').get('userId')),
				switchFlag: false,
				form1: {},
				pageSizeArray: [10, 20, 50],
				pagedata: {
					total: 0,
					pageSize: 10,
					currentPage: 1,
				},
				dataTable: [],
				columns1: [{
						title: "序号",
						width: 80,
						align: "center",
						fixed: 'left',
						render: (h, params) => {
							return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata
								.pageSize + 1);
						}
					},
					{
						title: '车辆名称',
						minWidth: 150,
						align: 'center',
						fixed: 'left',
						key: 'carName',
					},
					{
						title: '车牌号',
						minWidth: 150,
						align: 'center',
						key: 'plateNumber',
					},
					{
						title: '车辆编号',
						minWidth: 150,
						align: 'center',
						key: 'serialNumber',
					}, {
						title: '车身颜色',
						minWidth: 150,
						align: 'center',
						key: 'carColor',
					},
					{
						title: '车辆类型',
						minWidth: 150,
						align: 'center',
						key: 'carTypeName',
					},
					{
						title: '当前状态',
						minWidth: 150,
						align: 'center',
						key: 'carStatusName',
					},
					{
						title: '车辆性质',
						minWidth: 150,
						align: 'center',
						key: 'carPropertyName',
					},
					{
						title: '型号',
						minWidth: 150,
						align: 'center',
						key: 'carModel',
					},
					{
						title: '燃油类别',
						minWidth: 150,
						align: 'center',
						key: 'gasTypeName',
					},
					{
						title: '操作',
						key: 'action',
						fixed: 'right',
						width: 200,
						align: 'center',
						render: (h, params) => {
							let currentUser=JSON.parse(sessionStorage('userId').get('userId'));
							if(currentUser.loginId === this.Common.admin || currentUser.userId === params.row.createUserId  || currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
									||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined){
								return h('div', [
									h('A', {
										props: {
											type: 'primary',
											size: 'small'
										},
										style: {
											fontSize: '14px',
										},
										on: {
											click: () => {
												this.showData(params, 1);
											}
										}
									}, '详情'), h('Divider', {
										props: {
											type: 'vertical',
										}
									}, ''),
									h('A', {
										props: {
											type: 'primary',
											size: 'small'
										},
										style: {
											fontSize: '14px',
										},
										on: {
											click: () => {
												this.showData(params, 2);
											}
										}
									}, '修改'), h('Divider', {
										props: {
											type: 'vertical',
										}
									}, ''),
									h('A', {
										props: {
											type: 'error',
											size: 'small'
										},
										style: {
											fontSize: '14px',
											color: 'red',
										},
										on: {
											click: () => {
												this.$Modal.confirm({
													title: '提示',
													content: '<p>是否要删除？</p>',
													onOk: () => {
														this.deleteData(params);
													},
													onCancel: () => {}
												});
											}
										}
									}, '删除')
								]);
							}else{
								return h('div', [
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.showData(params, 1);
								            }
								        }
								    }, '详情'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
											color: '#c5c8ce'
								        },
								    }, '修改'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								            color: '#c5c8ce'
								        }
								    }, '删除')
								]);
							}
						}
					},

				],
				ruleCustom: {
					purchaseDate: [{
						validator: (rule, value, callback) => {
							if (value == null || value == '' || value == undefined) {
								callback(' ')
							} else {
								callback()
							}
						},
						required: true,
						trigger: 'change'
					}],
					carName: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					serialNumber: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					plateNumber: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					carTypeId: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					carStatusId: [{
						required: true,
						message: '  ',
						trigger: 'change'
					}],
					carPropertyId: [{
						required: true,
						message: '  ',
						trigger: 'change'
					}],
					carModel: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					gasTypeId: [{
						required: true,
						message: '  ',
						trigger: 'change'
					}],
					belongOrgId: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					inspectDate: [{
						validator: (rule, value, callback) => {
							if (value == null || value == '' || value == undefined) {
								callback(' ')
							} else {
								callback()
							}
						},
						required: true,
						trigger: 'change'
					}],
					workOrgId: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
				},
				add: false,
				model1: false,
				buttonLoading: false,
				model2: false,
				showdata: {},
				form1datacopy: {},
				carStatusList: [],
				carTypeList: [],
				gasTypeList: [],
				carPropertyList: [],
				loading: false,
				tableHeight: 10,
				currentOrgId: '',
				currentOrgName: '',
			}
		},
		mounted() {
			this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
			this.selectCodingSort();
			this.query();
		},
		methods: {
			deleteData(params) {
				let url = Api.deleteEqCarInfo;
				this.$http.delete(url + '/' + params.row.eqId, {
					params: {}
				}).then((res) => {
					if (res.data.status === 200) {
						this.$Message.success('成功');
						this.query()
					} else if (res.data.status === 201) {
						this.$Message.error(res.data.msg);

					}
				}).catch(e => {
					this.$Message.error('请求失败' + e);
				})
			},
			setOrgId(data) {
				this.form1datacopy.belongOrgId = data[data.length - 1];
			},
			setOrgName(data) {
				this.form1datacopy.orgName = data;
			},

			setWorkOrgId(data) {
				this.form1datacopy.workOrgId = data[data.length - 1];
			},
			setWorkOrgName(data) {
				this.form1datacopy.workOrgName = data;
			},

			getSelectRows(rows) {
				this.deleteRows = rows;
			},
			addInfo() {
				this.form1datacopy = {
					belongOrgId: sessionStorage('userId').getObject('userId').companyId,
					orgName: sessionStorage('userId').getObject('userId').companyName,
					workOrgId: sessionStorage('userId').getObject('userId').companyId,
					workOrgName: sessionStorage('userId').getObject('userId').companyName,
					carLen: 0,
					carWidth: 0,
					carHeight: 0,
					carWeight: 0
				};
				this.currentOrgId = '';
				this.currentOrgName = '';
				this.model1 = true;
				this.add = true;
			},
			pageChange(pageNum) {
				this.pagedata.currentPage = pageNum;
				this.query();
			},
			pageSizeChange(pageSize) {
				this.pagedata.pageSize = pageSize;
				this.query();
			},
			handleCancel() {
				this.form1datacopy = {};
				this.model1 = false;
			},
			selectCodingSort() {
				this.$http.get(Api.queryCodeDetailBySortId + '/EQ-000015', {
					params: {}
				}).then((res) => {
					this.carStatusList = res.data.data;
				});
				this.$http.get(Api.queryCodeDetailBySortId + '/EQ-000014', {
					params: {}
				}).then((res) => {
					this.carTypeList = res.data.data;
				});
				this.$http.get(Api.queryCodeDetailBySortId + '/EQ-000016', {
					params: {}
				}).then((res) => {
					this.carPropertyList = res.data.data;
				});
				this.$http.get(Api.queryCodeDetailBySortId + '/EQ-000017', {
					params: {}
				}).then((res) => {
					this.gasTypeList = res.data.data;
				});

			},
			switchQuery(flag) {
				this.switchFlag = flag;
				if (!this.switchFlag) {
					this.tableHeight = this.tableHeight + 44;
				} else {
					this.tableHeight = this.tableHeight - 44;
				}
			},
			reset() {
				this.form1 = {}
				this.query()
			},
			query() {
				this.loading = true;
				let orgId = sessionStorage('userId').getObject('userId').companyId;
				let data = {
					startPage: this.pagedata.currentPage,
					size: this.pagedata.pageSize,
					orgId: orgId
				};
				data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));

				let url = Api.queryEqCarInfo;
				this.$http.get(url, {
					params: data
				}).then((res) => {
					if (res.data.status === 201) {
						this.$Message.error(res.data.msg);
					}
					this.dataTable = res.data.data.data;
					this.pagedata.total = res.data.data.totalSize;
					this.loading = false;
				}).catch(e => {
					this.$Message.error("数据获取失败")
				})
			},
			showData(data, flag) {
				this.currentOrgId = data.row.belongOrgId;
				this.currentOrgName = data.row.orgName;
				if (flag == 1) {
					//查看页面
					this.showdata = data.row;
					this.showdata.purchaseDate = this.formatDate(new Date(this.showdata.purchaseDate), 'yyyy-MM-dd');
					this.showdata.inspectDate = this.formatDate(new Date(this.showdata.inspectDate), 'yyyy-MM-dd');
					this.model2 = true;
				} else {
					//修改页面
					this.add = false;
					this.form1datacopy = JSON.parse(JSON.stringify(data.row));
					this.model1 = true;
				}
			},
			formatDate(date, fmt) {
				if (/(y+)/.test(fmt)) {
					fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
				}
				let o = {
					'M+': date.getMonth() + 1,
					'd+': date.getDate(),
					'h+': date.getHours(),
					'm+': date.getMinutes(),
					's+': date.getSeconds()
				};
				for (let k in o) {
					if (new RegExp(`(${k})`).test(fmt)) {
						let str = o[k] + '';
						fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
					}
				}
				return fmt;
			},
			submit(name) {
				this.$refs[name].validate((valid) => {
					if (valid) {
						this.buttonLoading = true
						this.form1datacopy.purchaseDate = this.formatDate(new Date(this.form1datacopy
							.purchaseDate), 'yyyy-MM-dd');
						this.form1datacopy.inspectDate = this.formatDate(new Date(this.form1datacopy.inspectDate),
							'yyyy-MM-dd');
						let userId = sessionStorage('userId').getObject('userId').userId;
						let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
						if (this.add) {
							this.form1datacopy.createOrgId = orgId;
							this.form1datacopy.createUserId = userId;
							this.$http.post(Api.addEqCarInfo, this.form1datacopy).then((res) => {
								if (res.data.status === 200) {
									this.$Message.success('成功');
									this.model1 = false;
									this.query()
								} else if (res.data.status === 201) {
									this.$Message.error(res.data.msg);
									this.model1 = false;
								}
								this.buttonLoading = false
							}).catch(e => {
								this.model1 = false;
								this.query();
								this.buttonLoading = false
								this.$Message.error("数据获取失败")
							})
						} else {
							this.form1datacopy.updateOrgId = orgId;
							this.form1datacopy.updateUserId = userId;
							this.$http.post(Api.updateEqCarInfo, this.form1datacopy).then((res) => {
								if (res.data.status === 200) {
									this.$Message.success('成功');
									this.model1 = false;
									this.query()

								} else if (res.data.status === 201) {
									this.$Message.error(res.data.msg);
									this.model1 = false;

								}
								this.buttonLoading = false
							}).catch(e => {
								this.model1 = false;
								this.query();
								this.buttonLoading = false
								this.$Message.error("数据获取失败")
							})
						}
					} else {
						this.$Message.error('请填报完整!');
					}
				})
			},
			padLeftZero(str) {
				return ('00' + str).substr(str.length);
			},
			exportFormSubmit() {
				this.buttonLoading=true
				let orgId = sessionStorage('userId').getObject('userId').companyId
				let data = {
				    orgId:orgId,
				};
				data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
				this.$http.get(Api.exportCarInfo, {
				    params:data,
				    responseType: 'blob'      //告诉服务器我们需要的响应格式
				}).then((res) => {
				    const aLink = document.createElement("a");
				    let blob = new Blob([res.data], {
				        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
				    });
				    aLink.href = URL.createObjectURL(blob)
				    aLink.download = "车辆信息("+ this.formatDate(new Date(), "yyyy-MM-dd")+ ").xlsx" //标题
				    aLink.click()
				    document.body.appendChild(aLink)
				    this.buttonLoading=false
				})
			},
			formatDate(date, fmt) {
			    if (/(y+)/.test(fmt)) {
			        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
			    }
			    let o = {
			        'M+': date.getMonth() + 1,
			        'd+': date.getDate(),
			        'h+': date.getHours(),
			        'm+': date.getMinutes(),
			        's+': date.getSeconds()
			    };
			    for (let k in o) {
			        if (new RegExp(`(${k})`).test(fmt)) {
			            let str = o[k] + '';
			            fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
			        }
			    }
			    return fmt;
			},
		},
		watch: {
			"model1": function(qw, er) {
				if (qw && this.model1) {
					setTimeout(() => {
						this.$refs.carOrg.setCurrentOrg();
						this.$refs.workOrg.setCurrentOrg();
					}, 100)
				} else {
					this.$refs.carOrg.setCurrentOrg();
					this.$refs.workOrg.setCurrentOrg();
				}
			},
		},

	}
</script>

<style lang='css' scoped>
	@import '../../../../index.css';
</style>
